package written.test;

import java.util.*;

/**
 * @Author: Dang Qi
 * @Date: 2021/4/11  20:02
 * @Description:
 */
public class Baidu2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), p = sc.nextInt();
        beatMap = new HashMap<>();
        lostM = new HashSet<>();
        beatM = new HashSet<>();
        for(int i = 0; i < m; i++){
            int k = sc.nextInt(), v = sc.nextInt();
            Set<Integer> set = beatMap.get(k);
            if(set == null){
                set = new HashSet<>();
                beatMap.put(k, set);
            }
            set.add(v);
        }
        addBeats(p);
        addBeatM(p);
       // System.out.println(lostM.size()+ "&&"+beatM.size());
        int front = beatM.size(), behind = lostM.size();
        StringBuilder sb = new StringBuilder(String.valueOf(front+1));
        for(int i = front + 2; i <= n - behind; i++){
            sb.append(" "+i);
        }
        System.out.println(sb);
    }
    static  Map<Integer, Set<Integer>> beatMap;
    static Set<Integer> lostM;
    static Set<Integer> beatM;
    public static void addBeats(int per){
        Set<Integer> mBeat = beatMap.get(per);
        if(mBeat==null ) return;
        Iterator<Integer> iter = mBeat.iterator();
        while (iter.hasNext()){
            Integer one = iter.next();
            if(!lostM.contains(one)){
                lostM.add(one);
                addBeats(one);
            }
        }
    }
    public static void addBeatM(int m){
        for(Map.Entry<Integer, Set<Integer>> e: beatMap.entrySet()){
            if(e.getValue()!=null && e.getValue().contains(m)){
                beatM.add(e.getKey());
                addBeatM(e.getKey());
            }
        }
    }
}
